package com.ktjiaoyu.crm.repository;

import com.ktjiaoyu.crm.pojo.User;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface UserRepository extends JpaRepository<User,Long>,JpaSpecificationExecutor<User> {
    //此方法对应User实体类中的命名查询
    //如果希望根据接口方法名来实现数据库操作，则命名为：findUserByUsrName
    List<User> findUsersByName(String usrName);
    List<User> findByUsrNameLike(String usrName);

    @Query("select u from User u where u.usrRoleId=?1")
    List<User> findByRoleId(Long roleId);

    /**
     * 分页查询
     */
    @Query("select u from User u where u.usrRoleId=?1")
    Page<User> findPageByUsrRoleId(Long roleId,Pageable pageable);
}
